﻿define([],
function () {
    'use strict';

    return {

        /* Test for types */
        isDefined: function (o) {

            return typeof o != 'undefined' && o !== null;
        },

        isString: function (o) {

            return typeof o == 'string';
        },

        isNumber: function (o) {

            return !isNaN(o);
        },

        isArray: function (o) {

            return Array.isArray(o);
        },

        isDomNode: function (o) {

            return this.isDefined(o) && this.isDefined(o.nodeType);
        },

        isDate: function (o) {

            return o instanceof Date && !isNaN(o.valueOf());
        },

        isFunction: function (o) {

            return typeof o === 'function';
        },

        isEmpty: function (o) {

            return Object.keys(o).length === 0;
        },

        isPrimitive: function (o) {

            return typeof o == 'undefined'
                || typeof o == 'null'
                || typeof o == 'boolean'
                || typeof o == 'string'
                || typeof o == 'number';
        },

        // Tests whether the object is a plain one
        isObject: function (o) {

            return Object.prototype.toString.call(o) == '[object Object]';
        },

        isJSON: function (o) {

            if (this.isString(o)) {

                try {

                    JSON.parse(o);
                }
                catch (e) {

                    return false;
                }

                return true;
            }
            else {

                return false;
            }
        }


    };
});